package com.csjy.migration.hnnd.business;

import com.csjy.migration.hnnd.*;
import com.csjy.migration.hnnd.annotation.BusinessDataConverter;
import com.csjy.migration.hnnd.dict.BpmBizTitle;
import com.csjy.migration.hnnd.dict.BpmFormKey;
import com.csjy.migration.hnnd.dict.FormContentUrl;
import com.csjy.migration.hnnd.dict.ProcessBusConfig;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.*;

/**
 * T_S_BASEBUS
 */
@BusinessDataConverter(
    insertSql = "INSERT INTO T_S_BASEBUS\n" +
        "(USERID, TYPEID, PRJSTATEID, BUSCONFIGID, ID, CREATETIME)\n" +
        "VALUES(?, ?, ?, ?, ?, ?)",
    updateSql = "UPDATE ACT_HI_PROCINST " +
        "           SET PROC_INST_ID_=?, BUSINESS_KEY_=?, PROC_DEF_ID_=?, START_TIME_=?, END_TIME_=?, DURATION_=?, START_USER_ID_=?, START_ACT_ID_=?, END_ACT_ID_=?, SUPER_PROCESS_INSTANCE_ID_=?, DELETE_REASON_=?, TENANT_ID_=?, PROCESS_STOP_CAUSE_=? " +
        "           WHERE ID_ = ?",
    findMigratedIdListSql = "SELECT ID_ FROM ACT_HI_PROCINST WHERE TENANT_ID_ = ? ",
    seq = 501
)
public class TSBasebus extends AbstractBusiness {

  public TSBasebus(DbUtil sourceDbUtil, DbUtil targetDbUtil, SourceBusinessData sourceData, ProgramArgument programArgument, String projectId) throws SQLException {
    super(sourceDbUtil, targetDbUtil, sourceData, programArgument, projectId);
  }

  @Override
  public void migrate() throws Exception {

  }

  public void customMigrate(Map procInstRow) throws Exception {
    this.targetDbUtil.updateByParams("delete from t_s_basebus where id = '"+procInstRow.get("ID_")+"-JW'" ,new ArrayList());
    List values = new ArrayList();
    // USERID
    values.add(BusinessTool.getTaskRealActorId(procInstRow.get("CREATEPERSON").toString(), procInstRow.get("BEGINTIME")));
    // TYPEID
    values.add(null);
    //PRJSTATEID
    values.add("2");
    //BUSCONFIGID
    values.add(DictTool.getTargetDictCode(ProcessBusConfig.class,BusinessTool.getWorkflowRealWfName(procInstRow)));
    //ID
    values.add(procInstRow.get("ID_")+"-JW");
    //CREATETIME
    values.add(null);
    this.targetDbUtil.updateByParams(this.insertSql, values, false);
  }
}
